package yhp.com.zijie.service.impl;

import yhp.com.zijie.bean.Menu;
import yhp.com.zijie.bean.Role;
import yhp.com.zijie.dao.MiddleDao;
import yhp.com.zijie.dao.RoleDao;
import yhp.com.zijie.dao.impl.MiddleDaoImpl;
import yhp.com.zijie.dao.impl.RoleDaoImpl;
import yhp.com.zijie.service.RoleService;

import java.util.List;

public class RoleServiceImpl implements RoleService {

    private RoleDao roleDao = new RoleDaoImpl();
    private MiddleDao middleDao = new MiddleDaoImpl();

    @Override
    public List<Role> getRoles(int pageIndex, int pageSize) {
        return roleDao.getRoles(pageIndex , pageSize);
    }

    @Override
    public int total() {
        return roleDao.total();
    }

    @Override
    public int insertRole(String roleName, String state, String[] menuIds) {

        int i = 0;

        try {
            Role role = new Role();
            role.setRoleName(roleName);
            role.setRoleState(Integer.parseInt(state));

            int k = roleDao.insertRole(role);

            //2 新增中间的表，
            i = middleDao.insertMiddle(k, menuIds);

        } catch (NumberFormatException e) {
            e.printStackTrace();
        }


        return  i;
    }


}
